package ltd.followkba.comment;


import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.BufferedInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import ltd.advskin.utils.SubUtils;
import ltd.advskin.utils.SysUtils;
import ltd.followkba.comment.bean.BCommInfo;
import ltd.followkba.comment.bean.BOldRankInfo;
import ltd.followkba.comment.bean.BSongInfo;
import ltd.followkba.comment.bean.BUserInfo;
import ltd.followkba.comment.utils.CFileDbs;
import ltd.followkba.comment.utils.CodeBase64;
import main.MAPI;

import static ltd.advskin.MSKIN.MSTRING;
import static ltd.followkba.comment.MKCC.APPC_ADD_CARE;
import static ltd.followkba.comment.MKCC.APPC_AGREEMENT;
import static ltd.followkba.comment.MKCC.APPC_BOOT_AD;
import static ltd.followkba.comment.MKCC.APPC_BOOT_FRIST;
import static ltd.followkba.comment.MKCC.APPC_DEL_CARE;
import static ltd.followkba.comment.MKCC.APPC_GET_COMMENT_LIST;
import static ltd.followkba.comment.MKCC.APPC_GET_COMMENT_USERID;
import static ltd.followkba.comment.MKCC.APPC_GET_RANK_LIST;
import static ltd.followkba.comment.MKCC.APPC_GET_SONG_INFO;
import static ltd.followkba.comment.MKCC.APPC_GET_SONG_LIST;
import static ltd.followkba.comment.MKCC.APPC_GET_USER_INFO;
import static ltd.followkba.comment.MKCC.APPC_MODIFY_ME;
import static ltd.followkba.comment.MKCC.APPC_NEW_FLOWER;
import static ltd.followkba.comment.MKCC.APPC_PUSH_MAP;
import static ltd.followkba.comment.MKCC.APPC_PUT_COMMENT;
import static ltd.followkba.comment.MKCC.APPC_PUT_FLOWER;
import static ltd.followkba.comment.MKCC.APPC_REGISTER_MAIL;
import static ltd.followkba.comment.MKCC.APPC_REMIND;
import static ltd.followkba.comment.MKCC.APPC_SAY_HELLO;
import static ltd.followkba.comment.MKCC.APPC_SEARCH_USER;
import static ltd.followkba.comment.MKCC.APPC_UPLOAD_JPG1;
import static ltd.followkba.comment.MKCC.APPC_UPLOAD_JPG2;
import static ltd.followkba.comment.MKCC.APPC_UPLOAD_MP3A;
import static ltd.followkba.comment.MKCC.APPC_UPLOAD_MP3B;
import static ltd.followkba.comment.MKCC.APPC_USER_LOGIN;
import static ltd.followkba.comment.MKCC.APPC_WANT_RANK;
import static ltd.followkba.comment.MKCC.cKCB_SW_HAOCHANG;
import static ltd.advskin.MSKIN.MLOGE;

public class KgHaoChang extends KgAppBase{
    public final static int HTTP_GET = 0x01;
    public final static int HTTP_POST = 0x02;
    public final static int POST_PUT = 0x04;
    public final static int POST_DELETE = 0x08;
    public final static int GET_REMIND = 0x10;
    public final static int NO_LOGIN = 0x40;
    public final static int HAVE_SONG_USER_MIN = 10011000;
    public final static int HAVE_SONG_USER_MAX = 13000000;


    public KgHaoChang(){
        SwitchAppType(cKCB_SW_HAOCHANG);
        CFileDbs haveSongDbs = new CFileDbs(gsHaveSongUserDbs);
        if (haveSongDbs.mCounter < HAVE_SONG_USER_MIN || haveSongDbs.mCounter > HAVE_SONG_USER_MAX){
            Random random = new Random();
            haveSongDbs.mCounter = HAVE_SONG_USER_MIN + Math.abs(random.nextInt()) % (HAVE_SONG_USER_MAX - HAVE_SONG_USER_MIN);
            haveSongDbs.writeCounter();
        };
        haveSongDbs.close();

    }

    @Override
    public void SwitchUser(String mixAccount, String longitude, String latitude){
        int g4Local_1 = mixAccount.indexOf("#");
        if (g4Local_1 > 0) {
            mixAccount = mixAccount.substring(0, g4Local_1);
        }
        g4Local_1 = mixAccount.indexOf(",");
        if (g4Local_1 > 0) {
            gsUserID = mixAccount.substring(0, g4Local_1);
        }
        gsMixAccount = mixAccount;
        if ("".equals(longitude) || "".equals(latitude)){
            SetLongitudeLatitude(0);
        }
        else {
            gsLatitude = latitude;
            gsLongitude = longitude;
        }
        Random random = new Random();
        int g4Random = Math.abs(random.nextInt());
        gs_cli_model = String.format("%s-%04d", MUTIL.GET_MOBIL_BRAND(-1), g4Random % 10000);
        gs_cli_uniqid = MUTIL.GET_MD5_STRING(gsUserID).substring(0, 16);
//        gs_cli_uniqid = "8543f0783d111f37";
//        WriteCommand(APPC_BOOT_FRIST, "", "");
//        WriteCommand(APPC_BOOT_AD, "", "");
//        WriteCommand(APPC_AGREEMENT, "", "");
    }
    @Override
    public BUserInfo GetUserFullInfo(String mixAccount, BUserInfo beforeUserInfo){
        if ("".equals(mixAccount)){
            mixAccount = gsUserID;
        }
        else {
            int g4Local_1 = mixAccount.indexOf("#");
            if (g4Local_1 > 0) {
                mixAccount = mixAccount.substring(0, g4Local_1);
            }
            g4Local_1 = mixAccount.indexOf(",");
            if (g4Local_1 > 0) {
                mixAccount = mixAccount.substring(0, g4Local_1);
            }
        }
        BUserInfo aUserInfo = null;
        ResultNet resultNet;
        String beforeTime = "";
        if (beforeUserInfo == null) {
            resultNet = WriteCommand(APPC_GET_USER_INFO, mixAccount, "");
//MSTRING("GetUserFullInfo " + mixAccount + resultNet.message);
            if (resultNet.sucess && resultNet.result.size() > 0) {
                aUserInfo = (BUserInfo) resultNet.result.get(0);
            }
            else if (resultNet.message.indexOf("2106") > 0){
//MDWORD(0x99);
                aUserInfo = new BUserInfo();
                aUserInfo.userID = "2106";
                aUserInfo.nickName = resultNet.message;
                return aUserInfo;
            }
        }
        else {
            aUserInfo = beforeUserInfo;
            beforeTime = beforeUserInfo.beforeTime;
        }
        if (aUserInfo != null) {
            if ("end".equals(beforeTime)){        // 所有歌曲列表已经读取
                return aUserInfo;
            }
            resultNet = WriteCommand(APPC_GET_SONG_LIST, mixAccount, beforeTime);
            if (beforeUserInfo == null){
                 if (resultNet.result == null || resultNet.result.size() == 0){
                     resultNet = WriteCommand(APPC_GET_SONG_LIST, mixAccount, "0");
                 }
            }
            if (resultNet.result != null && resultNet.result.size() > 0) {
                aUserInfo.songQty += resultNet.result.size();
//MSTRING(resultNet.result.size());
                if (aUserInfo.songIDs == null) {
                    aUserInfo.songIDs = new ArrayList<>();
                }
                aUserInfo.songIDs.addAll(resultNet.result);
                aUserInfo.beforeTime = resultNet.message;
                if ((resultNet.result.size() % 10) != 0){         // 结束
                    aUserInfo.beforeTime = "end";
                }
            }
            if (aUserInfo.songIDs != null && aUserInfo.newSong == null) {
                aUserInfo.newSong = GetSongInfo(aUserInfo.songIDs.get(0));
            }
//MSTRING("aUserInfo.beforeCounter "+aUserInfo.beforeCounter);
            return aUserInfo;
        }
        return null;
    }
    @Override
    public BSongInfo GetSongInfo(String SongID){
        if (!"".equals(SongID)) {
            ResultNet resultNet = WriteCommand(APPC_GET_SONG_INFO, SongID, "");
            if (resultNet.sucess && resultNet.result.size() > 0) {
                return (BSongInfo) resultNet.result.get(0);
            }
        }
        return null;
    }
    @Override
    public String CheckLogin(){
        ResultNet resultNet = WriteCommand(APPC_REMIND, "", "");
        MSTRING("CheckLogin "+resultNet.sucess);
        if (resultNet.sucess) {
            return "ok";
        }
        String gsLocal_1 = "";
        if (resultNet.message.indexOf("2106") > 0){
            gsLocal_1 = "帐号异常：" + resultNet.message;
        }
        else if (resultNet.message.indexOf("4001") > 0 ){
            gsLocal_1 = "重新登录：" + resultNet.message;
        }
        return gsLocal_1;
    }
    @Override
    public String LoginSvr(String account, String password, String authCode){
        ResultNet resultNet = WriteCommand(APPC_USER_LOGIN, account, password);
        if (resultNet.sucess){
            return "ok";
        }
        return resultNet.message;
    }
    @Override
    public String PutCommentToSong(String userID, String songID, String commentID, String comment){
        ResultNet resultNet = WriteCommand(APPC_PUT_COMMENT, commentID, comment);
        if (resultNet.sucess){
            return "ok";
        }
        return resultNet.message;
    }
    @Override
    public String PutFlowerToSong(String songID){
        ResultNet resultNet = WriteCommand(APPC_PUT_FLOWER, songID, "");
        if (resultNet.sucess){
            return resultNet.message;
        }
        return "0";
    }
    @Override
    public String AddCareUser(String userID){
        ResultNet resultNet = WriteCommand(APPC_ADD_CARE, userID, "");
        if (resultNet.sucess){
            return "ok";
        }
        return resultNet.message;
    }
    @Override
    public ResultNet GetRankList(){
        String province = SetLongitudeLatitude(0);
//        WriteCommand(APPC_PUSH_MAP, "", "");
        int g4Local_1 = mRankCounter % 78;      // 只有75个地区榜
//        g4Local_1=78;
        switch (g4Local_1){
            case 0: province = "新歌"; break;
            case 1: province = "火星"; break;
            case 2: province = "全国"; break;
            default:
                province = String.format("%d", g4Local_1 - 3);
                break;
        }
        ResultNet resultNet = WriteCommand(APPC_GET_RANK_LIST, province, "");
        resultNet.message = province;
        return resultNet;
    }
    @Override
    public ResultNet GetCommentList(int counter, String userID, String SongID, String commentID){
        if (counter == -1) {
            return WriteCommand(APPC_GET_COMMENT_USERID, commentID, "");
        }
        return WriteCommand(APPC_GET_COMMENT_LIST, commentID, "");
    }
    @Override
    public String ModifyUseInfo(int retry, BUserInfo aUserInfo) {
        ResultNet resultNet;
        String gsLocal_1 = "";
        String gsLocal_2 = "";
        int g4Local_1 = 0;
        do {
            if (g4Local_1 == 0) {
                gsLocal_1 = "&nickname=" + aUserInfo.nickName;
                gsLocal_2 = "&nickname=" + URLEncoder.encode(aUserInfo.nickName);
            }
            else {
                gsLocal_1 = "&nickname=" + MUTIL.GET_RANDOM_PASSWORD();
                gsLocal_2 = gsLocal_1;
            }
            gsLocal_1 += "&Intro=" + aUserInfo.intro;
            gsLocal_2 += "&Intro=" + URLEncoder.encode(aUserInfo.intro);

            gsLocal_1 += "&longitude=" + aUserInfo.longitude;
            gsLocal_2 += "&longitude=" + aUserInfo.longitude;
            gsLocal_1 += "&latitude=" + aUserInfo.latitude;
            gsLocal_2 += "&latitude=" + aUserInfo.latitude;

            gsLocal_1 += "&Province=" + aUserInfo.province;
            gsLocal_2 += "&Province=" + URLEncoder.encode(aUserInfo.province);
            gsLocal_1 += "&City=" + aUserInfo.city;
            gsLocal_2 += "&City=" + URLEncoder.encode(aUserInfo.city);
            if (g4Local_1 == 0) {
                gsLocal_1 += "&Gender=" + aUserInfo.gender;
                gsLocal_2 += "&Gender=" + aUserInfo.gender;
            }
            resultNet = WriteCommand(APPC_MODIFY_ME, gsLocal_1, gsLocal_2);
            if (resultNet.sucess){
                return "ok";
            }
            else {
                MSTRING("用户信息出错：" + resultNet.message);
            }
        } while (++g4Local_1 < retry);
        return resultNet.message;
    }
    @Override
    public String FetchFlower(){
        ResultNet resultNet = WriteCommand(APPC_NEW_FLOWER, "", "");
        return resultNet.message;
    }
    @Override
    public List<String> SearchUser(int type, String user) {
        if (type == 0){
            ResultNet resultNet = WriteCommand(APPC_SEARCH_USER, user, "");
            if (resultNet.sucess){
                return resultNet.result;
            }
        }
        else {                                                  // 查找链接
        }
        return null;
    }
    @Override
    public String downloadHeadFile(BUserInfo aUserInfo) {
        aUserInfo.headFile = String.format("%s%d_%s.jpg", MKCS.gsPhotoPath, AppType, aUserInfo.userID);
        if (MAPI.GET_FILE_LENGTH(aUserInfo.headFile) < 100) {
//MLOG("downloadHeadFile "+aUserInfo.HeadFile);
            if (MUTIL.GET_URL_TO_FILE(aUserInfo.headUrl, aUserInfo.headFile) < 100) {
                return "error HeadFile";
            }
        }
        return "ok";
    }

    public ResultNet WriteCommand(int type, String aux1, String aux2){
        String gsLocal_1 = String.format("%d", System.currentTimeMillis() / 1000);
        String gsLocal_2;
        String gsLocal_3;
        int g4Local_1;
        ResultNet resultNet = new ResultNet();
        switch (type) {
            case APPC_BOOT_FRIST:
                gsLocal_2 = MUTIL.GET_HAO_CHANG_SIGN(gsLocal_1, "&isFirst=0");
                gsLocal_3 = "/api/boot?_time=" + gsLocal_1 + gsLocal_2 + "&isFirst=0";
                gsLocal_1 = WriteToSvr(HTTP_GET, gsLocal_3 + "\r\n", "");
                MakeStdReturn(gsLocal_1, resultNet);
                break;
            case APPC_BOOT_AD:
                gsLocal_3 = "/api/boot/ad";
                gsLocal_1 = WriteToSvr(HTTP_GET, gsLocal_3 + "\r\n", "");
                MakeStdReturn(gsLocal_1, resultNet);
                break;
            case APPC_REMIND:
                gsLocal_2 = MUTIL.GET_HAO_CHANG_SIGN(gsLocal_1, "&lastNotifyTime=" + gsLocal_1);
                gsLocal_3 = "/api/remind?_time=" + gsLocal_1 + "&lastNotifyTime=" + gsLocal_1 + gsLocal_2;
                gsLocal_1 = WriteToSvr(HTTP_GET | GET_REMIND, gsLocal_3 + "\r\n", "");
                MakeStdReturn(gsLocal_1, resultNet);
//MLOG("APPC_REMIND "+LoginFlag+" "+gsLocal_1);
                break;
            case APPC_AGREEMENT:
                gsLocal_3 = "/api/agreement";
                gsLocal_1 = WriteToSvr(HTTP_GET, gsLocal_3 + "\r\n", "");
                MakeStdReturn(gsLocal_1, resultNet);
                break;
            case APPC_GET_USER_INFO:
                gsLocal_2 = MUTIL.GET_HAO_CHANG_SIGN(gsLocal_1, "&userId=" + aux1);
                gsLocal_3 = "/api/user/information?_time=" + gsLocal_1 + gsLocal_2 + "&userId=" + aux1;
                gsLocal_1 = WriteToSvr(HTTP_GET, gsLocal_3 + "\r\n", "");
//MLOG("APPC_GET_USER_INFO "+aux1+" "+gsLocal_1);
                if (MakeStdReturn(gsLocal_1, resultNet)){
                    List<BUserInfo> aUserInfos = new ArrayList<>();
                    BUserInfo aUserInfo = new BUserInfo();
//MDWORD(0x9a);MLOG(resultNet.nextJason);
                    aUserInfo.userID = aux1;
                    aUserInfo.nickName = MUTIL.GET_JSON_STRING(resultNet.nextJason, "nickname");
                   // gsLocal_2 = MUTIL.GET_JSON_STRING(resultNet.nextJason, "avatar");
//MLOG(aUserInfo.UserName);
                    aUserInfo.gender = MUTIL.GET_JSON_STRING(resultNet.nextJason, "Gender");
                    aUserInfo.intro = MUTIL.GET_JSON_STRING(resultNet.nextJason, "Intro");
                    //MLOG(aUserInfo.Gender);
//MLOG(aUserInfo.Gender);MLOG(aUserInfo.Intro);
                    gsLocal_3 = MUTIL.GET_JSON_STRING(resultNet.nextJason, "location");
                    aUserInfo.province = MUTIL.GET_JSON_STRING(gsLocal_3, "Province");
                    aUserInfo.city = MUTIL.GET_JSON_STRING(gsLocal_3, "City");
//    MLOG(aUserInfo.Province);
                    aUserInfo.latitude = MUTIL.GET_JSON_STRING(gsLocal_3, "latitude");
                    aUserInfo.longitude = MUTIL.GET_JSON_STRING(gsLocal_3, "longitude");

                    gsLocal_3 = MUTIL.GET_JSON_STRING(resultNet.nextJason, "followStatus");
                    aUserInfo.followed = MUTIL.GET_JSON_STRING(gsLocal_3, "followed");
                    aUserInfo.followMe = MUTIL.GET_JSON_STRING(gsLocal_3, "followMe");
                    aUserInfo.isSpecial = MUTIL.GET_JSON_STRING(gsLocal_3, "isSpecial");

                    gsLocal_3 = MUTIL.GET_JSON_STRING(resultNet.nextJason, "counter");
//MLOG(gsLocal_3);
//MDWORD(0x9a);MLOG(MUTIL.GET_JSON_STRING(gsLocal_3, "playlist"));MLOG(aUserInfo.WorksQty);
                    aUserInfo.fansQty = MUTIL.GET_JSON_STRING(gsLocal_3, "fans");
                    aUserInfo.flowerReceive = MUTIL.GET_JSON_STRING(gsLocal_3, "flowerReceive");
                    aUserInfo.careQty = MUTIL.GET_JSON_STRING(gsLocal_3, "follow");

                    gsLocal_3 = MUTIL.GET_JSON_STRING(resultNet.nextJason, "avatar");
                    aUserInfo.headUrl = MUTIL.GET_JSON_STRING(gsLocal_3, "original");

                    aUserInfos.add(aUserInfo);
                    resultNet.result = aUserInfos;
                }
                break;
            case APPC_GET_SONG_INFO:
                gsLocal_2 = MUTIL.GET_HAO_CHANG_SIGN(gsLocal_1, "&songId=" + aux1);
                gsLocal_3 = "/api/song?_time=" + gsLocal_1 + "&songId=" + aux1 + gsLocal_2;
                gsLocal_1 = WriteToSvr(HTTP_GET, gsLocal_3 + "\r\n", "");
//MLOG("APPC_GET_SONG_INFO("+aux1+") "+gsLocal_1);
//MLOG("song 1:" + gsLocal_3);MLOG("return 1:" + gsLocal_1);
                if (MakeStdReturn(gsLocal_1, resultNet)) {
                    BSongInfo aSongInfo = new BSongInfo();
                    gsLocal_2 = MUTIL.GET_JSON_STRING(resultNet.nextJason, "song");

                    aSongInfo.songID = MUTIL.GET_JSON_STRING(gsLocal_2, "songId");
                    aSongInfo.songName = MUTIL.GET_JSON_STRING(gsLocal_2, "name");
                    aSongInfo.intro = MUTIL.GET_JSON_STRING(gsLocal_2, "Intro");
                    aSongInfo.isMV = MUTIL.GET_JSON_STRING(gsLocal_2, "IsVideo");
                    aSongInfo.isKTV = MUTIL.GET_JSON_STRING(gsLocal_2, "isKTV");
                    aSongInfo.createTime = MUTIL.GET_JSON_STRING(gsLocal_2, "CreateTime");
                    aSongInfo.commentID = MUTIL.GET_JSON_STRING(gsLocal_2, "commentThreadId");

                    aSongInfo.beatId = (int) MUTIL.GET_JSON_VALUE(gsLocal_2, "beatId");
                    aSongInfo.wantRank = MUTIL.GET_JSON_STRING(gsLocal_2, "wantRank");
                    aSongInfo.wantRankTime = MUTIL.GET_JSON_STRING(gsLocal_2, "wantRankTime");
//MLOG(aSongInfo.IdS + aSongInfo.commentID);
                    gsLocal_3 = MUTIL.GET_JSON_STRING(gsLocal_2, "audio");
                    aSongInfo.path = MUTIL.GET_JSON_STRING(gsLocal_3, "file");
                    aSongInfo.duration = MUTIL.GET_JSON_STRING(gsLocal_3, "duration");

                    gsLocal_3 = MUTIL.GET_JSON_STRING(gsLocal_2, "counter");
                    aSongInfo.listenQty = MUTIL.GET_JSON_STRING(gsLocal_3, "play");
                    aSongInfo.flowerQty = MUTIL.GET_JSON_STRING(gsLocal_3, "flower");
                    aSongInfo.commentQty = MUTIL.GET_JSON_STRING(gsLocal_3, "comment");
                    aSongInfo.shareQty = MUTIL.GET_JSON_STRING(gsLocal_3, "share");

                    gsLocal_3 = MUTIL.GET_JSON_STRING(gsLocal_2, "tuning");
                    aSongInfo.humanVolume = MAPI.STRING_DEC32(MUTIL.GET_JSON_STRING(gsLocal_3, "humanVolume"));
                    aSongInfo.beatVolume = MAPI.STRING_DEC32(MUTIL.GET_JSON_STRING(gsLocal_3, "beatVolume"));


//MLOG(aSongInfo.duration);MLOG(aSongInfo.playQty);
                    gsLocal_2 = MUTIL.GET_JSON_STRING(resultNet.nextJason, "rankSummary");
                    JSONArray jsonArray = null;
                    try {
                        jsonArray = new JSONArray(gsLocal_2);
                        g4Local_1 = jsonArray.length();
                        if (g4Local_1 == 3){
                            JSONObject jsonObj = jsonArray.getJSONObject(0);
                            aSongInfo.rankName1 = jsonObj.getString("name");
                            aSongInfo.rankMax1 = jsonObj.getString("rank");

                            jsonObj = jsonArray.getJSONObject(1);
                            aSongInfo.rankName2 = jsonObj.getString("name");
                            aSongInfo.rankMax2 = jsonObj.getString("rank");

                            jsonObj = jsonArray.getJSONObject(2);
                            aSongInfo.rankName3 = jsonObj.getString("name");
                            aSongInfo.rankMax3 = jsonObj.getString("rank");

                        }
                        List<BSongInfo> aSongInfos = new ArrayList<>();
                        aSongInfos.add(aSongInfo);
                        resultNet.result = aSongInfos;
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
                break;

            case APPC_GET_SONG_LIST:
                if (gsUserID.equals(aux1)){                  // 自己的
                    gsLocal_2 = MUTIL.GET_HAO_CHANG_SIGN(gsLocal_1, "&filter=all");
                    gsLocal_3 = "/api/user/songs?_time=" + gsLocal_1 + gsLocal_2 + "&filter=all";
//MDWORD(0xa6);
                    aux2 = "songs";
                }                                           // 别人的
                else {
//MDWORD(0xa7);MLOG(aux2);
                    if ("".equals(aux2)){
                        gsLocal_2 = MUTIL.GET_HAO_CHANG_SIGN(gsLocal_1, "&userId=" + aux1);
                        gsLocal_3 = "/api/circle/user/timeline?_time=" + gsLocal_1 + gsLocal_2 + "&userId=" + aux1;
                    }
                    else if ("0".equals(aux2)){
                        gsLocal_2 = MUTIL.GET_HAO_CHANG_SIGN(gsLocal_1, "archive=1&type=all&userId=" + aux1);
                        gsLocal_3 = "/api/circle/user/timeline?archive=1&_time=" + gsLocal_1 + "&type=all" + gsLocal_2 + "&userId=" + aux1;
                    }
                    else {
                        gsLocal_2 = MUTIL.GET_HAO_CHANG_SIGN(gsLocal_1, "BeforeTime=" + aux2 + "&userId=" + aux1);
                        gsLocal_3 = "/api/circle/user/timeline?BeforeTime=" + aux2 + "&_time=" + gsLocal_1 + gsLocal_2 + "&userId=" + aux1;
//MLOG(gsLocal_3);
                    }
                    aux2 = "feeds";

                }
                gsLocal_1 = WriteToSvr(HTTP_GET, gsLocal_3 + "\r\n", "");
//MLOG("APPC_GET_SONG_LIST "+gsLocal_1);
                if (MakeStdReturn(gsLocal_1, resultNet)) {
                    List<String> aSongInfos = new ArrayList<>();
                    gsLocal_2 = MUTIL.GET_JSON_STRING(resultNet.nextJason, aux2);
                    g4Local_1 = 0;
                    int g4Local_2 = 0;
                    JSONArray jsonArray = null;
                    try {
                        jsonArray = new JSONArray(gsLocal_2);
                        g4Local_1 = jsonArray.length();

                        if (gsUserID.equals(aux1)) {
                            resultNet.message = MUTIL.GET_JSON_STRING(resultNet.nextJason, "songCount");
//MLOG("bbbb：" + resultNet.message);
                            while (g4Local_2 < g4Local_1) {
                                JSONObject jsonobject = jsonArray.getJSONObject(g4Local_2);
                                aSongInfos.add(jsonobject.getString("songId"));
                                ++g4Local_2;
                            }
//MLOG("aaa：" + g4Local_2);
                        }
                        else {

                            while (g4Local_2 < g4Local_1) {
                                JSONObject jsonobject = jsonArray.getJSONObject(g4Local_2);
                                gsLocal_3 = jsonobject.getString("shareCard");
                                resultNet.message = jsonobject.getString("CreateTime");
                                gsLocal_2 = MUTIL.GET_JSON_STRING(gsLocal_3, "song");
                                aSongInfos.add(MUTIL.GET_JSON_STRING(gsLocal_2, "songId"));
//MLOG("歌曲：" + MUTIL.GET_JSON_STRING(gsLocal_2, "songId") + " "+resultNet.message);
                                ++g4Local_2;
                            }
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                    if (g4Local_2 != g4Local_1){
//MLOG("APPC_GET_SONG_LIST不完整"+g4Local_2+"/"+g4Local_1);
                    }
                    resultNet.result = aSongInfos;
                }
                break;
            case APPC_GET_RANK_LIST :
                gsLocal_3 = "/api/rank/region";
                if ("火星".equals(aux1)){
                    gsLocal_1 = WriteToSvr(NO_LOGIN | HTTP_GET, gsLocal_3 + "\r\n", "");
                }
                else {
                    if ("新歌".equals(aux1)) {
                        gsLocal_3 = "/api/song/fresh";
                    } else if ("全国".equals(aux1)) {
                        gsLocal_3 = "/api/rank/nation";
                    } else if ("地区".equals(aux1)) {
                        gsLocal_3 = "/api/rank/regions";
                    }else {
//                        aux2="2";
                        gsLocal_2 = MUTIL.GET_HAO_CHANG_SIGN(gsLocal_1, "&rankId=" + aux1);
                        gsLocal_3 = "/api/rank/region?_time=" + gsLocal_1 + gsLocal_2 + "&rankId=" + aux1;

//                        /api/rank/region?_time=1529747459&_sign=b87d44302b64a996ca42a81507527744&rankId=2
                    }
                    gsLocal_1 = WriteToSvr(HTTP_GET, gsLocal_3 + "\r\n", "");
                }
//MLOG("APPC_READ_RANK A "+ aux1+" "+aux2+" "+gsLocal_1.length()+" "+gsLocal_3+" "+gsLocal_1);
                if (MakeStdReturn(gsLocal_1, resultNet)){
                    List<BOldRankInfo> topLists = new ArrayList<>();
                    try {
                        gsLocal_3 = MUTIL.GET_JSON_STRING(resultNet.nextJason, "songs");
                        MSTRING("APPC_READ_RANK "+ gsLocal_3);
                        JSONArray jsonArray = new JSONArray(gsLocal_3);
                        g4Local_1 = jsonArray.length();
                        int g4Local_2 = 0;
                        while (g4Local_2 < g4Local_1) {
                            JSONObject jsonobject = jsonArray.getJSONObject(g4Local_2);
                            BOldRankInfo bOldRankInfo = new BOldRankInfo();
                            bOldRankInfo.SongID = jsonobject.getString("songId");
                            bOldRankInfo.SongName = jsonobject.getString("title");
                            gsLocal_2 = jsonobject.getString("singer");
                            bOldRankInfo.UserID = MUTIL.GET_JSON_STRING(gsLocal_2, "userId");
                            bOldRankInfo.NickName = MUTIL.GET_JSON_STRING(gsLocal_2, "nickname");
                            topLists.add(bOldRankInfo);
//MLOG("APPC_READ_RANK A "+ bOldRankInfo.UserID+" "+bOldRankInfo.SongID);
                            ++g4Local_2;
                        }
                        resultNet.result = topLists;
//                        gsLocal_2 = String.format("打开好唱：%s %s(%s %s)榜，找到用户%d/%d个(%dB)", aux1, aux2, gsLongitude, gsLatitude, g4Local_2, g4Local_1, gsLocal_1.length());
//MLOG(gsLocal_2);gsLocal_2
//                        WriteToLogFile("APPC_READ_RANK "+ aux1+"("+gsUserID+")"+gsLocal_1.length()+" "+g4Local_2+"/"+g4Local_1);
                        MSTRING(String.format("找到好唱%s榜用户%d个", aux1, g4Local_2));
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
                break;

            case APPC_GET_COMMENT_LIST:
            case APPC_GET_COMMENT_USERID:
                gsLocal_2 = MUTIL.GET_HAO_CHANG_SIGN(gsLocal_1, "&threadId=" + aux1 + "&sort=desc");
                gsLocal_3 = "/api/comments?_time=" + gsLocal_1 + "&threadId=" + aux1 + gsLocal_2 + "&sort=desc";
                gsLocal_1 = WriteToSvr(HTTP_GET, gsLocal_3 + "\r\n", "");
//MLOG("APPC_GET_COMMENT_LIST "+gsLocal_1);
                if (MakeStdReturn(gsLocal_1, resultNet)) {
                    try {
                        gsLocal_3 = MUTIL.GET_JSON_STRING(resultNet.nextJason, "comments");
                        JSONArray jsonArray = new JSONArray(gsLocal_3);
                        g4Local_1 = jsonArray.length();
//MLOG(g4Local_1);
                        int g4Local_2 = 0;
                        int g4Local_3;
                        int g4Local_4;
                        if (type == APPC_GET_COMMENT_USERID){
                            List<String> commLists = new ArrayList<>();
                            JSONObject jsonobject;
                            while (g4Local_2 < g4Local_1) {
                                jsonobject = jsonArray.getJSONObject(g4Local_2);
                                commLists.add(jsonobject.getString("userId"));
                                ++g4Local_2;
                            }
                            resultNet.result = commLists;
                        }
                        else {
                            List<BCommInfo> commLists = new ArrayList<>();
                            while (g4Local_2 < g4Local_1) {
                                BCommInfo bCommInfo = MakeACommInfo(jsonArray, g4Local_2);
                                g4Local_3 = MAPI.STRING_DEC32(bCommInfo.totalReply);
//MLOG(bCommInfo.aUserInfo.HeadUrl);MLOG(bCommInfo.aUserInfo.UserIdS);
                                if (g4Local_3 > 0) {
                                    JSONObject jsonobject = jsonArray.getJSONObject(g4Local_2);
                                    gsLocal_2 = jsonobject.getString("sofa");
//MLOG("sofa " + gsLocal_2);
                                    bCommInfo.reply = new ArrayList<>();
                                    JSONArray arraySofa = new JSONArray(gsLocal_2);
                                    g4Local_3 = arraySofa.length();
                                    g4Local_4 = 0;
                                    while (g4Local_4 < g4Local_3) {
                                        bCommInfo.reply.add(MakeACommInfo(arraySofa, g4Local_4));
//MLOG("reply " + bCommInfo.reply.get(g4Local_4).aUserInfo.UserName+" "+bCommInfo.reply.get(g4Local_4).content);
                                        ++g4Local_4;
                                    }
                                }
                                commLists.add(bCommInfo);
                                ++g4Local_2;
                            }
                            resultNet.result = commLists;
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
                break;


            case APPC_USER_LOGIN:
//gsLocal_1 = "1475831712";
                gsMixAccount = "";
                SetLongitudeLatitude(0);
                gsLocal_2 = "&email=" + aux1 + "&password=" + aux2;
                gsLocal_3 = MUTIL.GET_HAO_CHANG_SIGN(gsLocal_1, gsLocal_2);
//MLOG(gsLocal_1 + gsLocal_3 + "&" + aux1 + "&" + aux2);
                gsLocal_3 = "_time=" + gsLocal_1 + gsLocal_3 + "&email=" + URLEncoder.encode(aux1) + "&password=" + aux2 ;
                gsLocal_1 = "/api/login/email";
                gsLocal_1 = WriteToSvr(HTTP_POST, gsLocal_1, gsLocal_3);
                MSTRING("APPC_USER_LOGIN:" + gsLocal_3 + " _ "+gsLocal_1);
               if (MakeStdReturn(gsLocal_1, resultNet)){
                    gsMixAccount = MUTIL.GET_JSON_STRING(resultNet.nextJason, "authorizeToken");
                    g4Local_1 = gsMixAccount.indexOf(",");
                    if (g4Local_1 > 0) {
                        gsUserID = gsMixAccount.substring(0, g4Local_1);
                        MSTRING("gsUserID:" + gsUserID);
                    }
                }
                else {
                   gsLocal_2 = MUTIL.GET_JSON_STRING(gsLocal_1, "errno");
                   if ("2129".equals(gsLocal_2)) {
                       MSTRING("邮箱不存在:" + aux1 + " " + aux2);
                   }
                }
                break;

            case APPC_SEARCH_USER:
                gsLocal_2 = MUTIL.GET_HAO_CHANG_SIGN(gsLocal_1, "&keyword=" + aux1);
                gsLocal_3 = "/api/users/by/keyword?_time=" + gsLocal_1 + gsLocal_2 + "&keyword=" + URLEncoder.encode(aux1);
                gsLocal_1 = WriteToSvr(HTTP_GET, gsLocal_3 + "\r\n", "");
                MSTRING("APPC_SEARCH_USER "+aux1+" "+gsLocal_1);
                if (MakeStdReturn(gsLocal_1, resultNet)) {
                    gsLocal_2 = MUTIL.GET_JSON_STRING(resultNet.nextJason, "users");
                    List<String> aUserLists = new ArrayList<>();
                    JSONArray jsonArray = null;
                    try {
                        jsonArray = new JSONArray(gsLocal_2);
                        g4Local_1 = jsonArray.length();
                        MSTRING("APPC_SEARCH_USER 2 "+g4Local_1+" "+gsLocal_2);
                        int g4Local_2 = 0;
                        while (g4Local_2 < g4Local_1) {
                            JSONObject jsonObj = jsonArray.getJSONObject(g4Local_2);
                            gsLocal_2 = jsonObj.getString("userId");
                            aUserLists.add(gsLocal_2);
//MLOG("APPC_SEARCH_USER 3"+gsLocal_2);
                            ++g4Local_2;
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                    resultNet.result = aUserLists;
                }
                MakeStdReturn(gsLocal_1, resultNet);
                break;
            case APPC_NEW_FLOWER:
                CFileDbs flowerTimeDbs = new CFileDbs(gsFlowerTimeFile);
                g4Local_1 = (int)(System.currentTimeMillis() / 1000);
                int g4Local_2 = flowerTimeDbs.GetUserID4Byte(gsUserID);
                flowerTimeDbs.close();
//MLOG("APPC_NEW_FLOWER "+g4Local_1+" "+g4Local_2);
                if (g4Local_1 > g4Local_2) {
                    gsLocal_3 = "/api/my/newflower";
                    gsLocal_1 = WriteToSvr(HTTP_GET, gsLocal_3 + "\r\n", "");
//MLOG("APPC_NEW_FLOWER B " + gsLocal_1);
                    if (MakeStdReturn(gsLocal_1, resultNet)) {
                        gsLocal_2 = MUTIL.GET_JSON_STRING(gsLocal_1, "serverTime");
                        gsLocal_3 = MUTIL.GET_JSON_STRING(resultNet.nextJason, "nextBonusFlowerTime");
                        g4Local_1 = MAPI.STRING_DEC32(gsLocal_2) + MAPI.STRING_DEC32(gsLocal_3);
                        gsLocal_1 = MUTIL.GET_JSON_STRING(resultNet.nextJason, "totalFlower");

                        CFileDbs cFileDbs = new CFileDbs(gsFlowerTimeFile);
                        cFileDbs.SetUserID4Byte(gsUserID, g4Local_1);
                        cFileDbs.close();

                        CFileDbs flowerRecoderDbs = new CFileDbs(gsFlowerQtyFile);
                        flowerRecoderDbs.SetUserID4Byte(gsUserID, MAPI.STRING_DEC32(gsLocal_1));
                        flowerRecoderDbs.close();

                        resultNet.message = gsLocal_1;
//MLOG(gsLocal_2+" " + gsLocal_3+" " + g4Local_1 +" " + resultNet.message);
                    }
                    else if ("2109".equals(MUTIL.GET_JSON_STRING(gsLocal_1, "errno"))) {
                        resultNet.sucess = true;
                        resultNet.message = MUTIL.GET_JSON_STRING(gsLocal_1, "error");
                    }
                }
                break;
            case APPC_REGISTER_MAIL:
                SetLongitudeLatitude(0);
                gsMixAccount = "";
//gsLocal_1 = "1471828265";
                gsLocal_2 = "&passwordAgain=" + aux2 + "&password=" + aux2 + "&email=" + aux1;
                gsLocal_3 = MUTIL.GET_HAO_CHANG_SIGN(gsLocal_1, gsLocal_2);
                //      MLOG(gsLocal_1 + gsLocal_3 + "&" + aux1 + "&" + aux2);
                gsLocal_3 = "_time=" + gsLocal_1 + "&passwordAgain=" + aux2 + gsLocal_3 + "&password=" + aux2 + "&email=" + URLEncoder.encode(aux1);
                gsLocal_1 = "/api/register/email";
                gsLocal_1 = WriteToSvr(HTTP_POST, gsLocal_1, gsLocal_3);
                if (MakeStdReturn(gsLocal_1, resultNet)){
                    gsMixAccount = MUTIL.GET_JSON_STRING(resultNet.nextJason, "authorizeToken");
                    g4Local_1 = gsMixAccount.indexOf(",");
                    if (g4Local_1 > 0) {
                        gsUserID = gsMixAccount.substring(0, g4Local_1);
                    }
                }
                break;
            case APPC_MODIFY_ME:
                gsLocal_2 = MUTIL.GET_HAO_CHANG_SIGN(gsLocal_1, aux1);
                //            MLOG(gsLocal_1 + gsLocal_3 + "&" + aux1 + "&" + aux2);
                gsLocal_3 = "_time=" + gsLocal_1 + gsLocal_2 + aux2;
                gsLocal_1 = "/api/me";
                gsLocal_1 = WriteToSvr(POST_PUT, gsLocal_1, gsLocal_3);
                MakeStdReturn(gsLocal_1, resultNet);
//MLOG("2:" + gsLocal_3);
//MLOG("return 2:" + gsLocal_1);
                break;
            case APPC_UPLOAD_JPG1:
//gsLocal_1="1477107455";
                gsLocal_2 = "[{\"filename\":\"" + aux1  + "\",\"size\":" + aux2 + "}]";
                gsLocal_3 = "&files=" + gsLocal_2 + "&bucket=avatar";
                gsLocal_3 = MUTIL.GET_HAO_CHANG_SIGN(gsLocal_1, gsLocal_3);
                gsLocal_2 = "_time=" + gsLocal_1 + gsLocal_3 + "&files=" + URLEncoder.encode(gsLocal_2) + "&bucket=avatar";
                gsLocal_1 = "/api/upload/transaction";
//gsLocal_2 = "_time=1475541114&_sign=454cfcf6b8f1d28f7aadd3dacd2910b5&files=%5B%7B%22filename%22%3A%22AM_11539554_14755411134227982.jpg%22%2C%22size%22%3A46175%7D%5D&bucket=avatar";
                gsLocal_1 = WriteToSvr(HTTP_POST, gsLocal_1, gsLocal_2);

//MLOG("2:" + gsLocal_2);
//MLOG("return 2:" + gsLocal_1);
                MakeStdReturn(gsLocal_1, resultNet);
                break;
            case APPC_UPLOAD_JPG2:
                gsLocal_2 = "&uploadResponse=" + aux1 + "&transactionId=" + aux2;
                gsLocal_3 = MUTIL.GET_HAO_CHANG_SIGN(gsLocal_1, gsLocal_2);
                gsLocal_2 = "_time=" + gsLocal_1 + gsLocal_3 + "&uploadResponse=" + URLEncoder.encode(aux1) + "&transactionId=" + aux2;
                gsLocal_1 = "/api/upload/transaction";
                gsLocal_1 = WriteToSvr(POST_DELETE, gsLocal_1, gsLocal_2);
//MLOG("return 3:" + gsLocal_1);
                MakeStdReturn(gsLocal_1, resultNet);
                break;
            case APPC_UPLOAD_MP3A:
                gsLocal_3 = MUTIL.GET_HAO_CHANG_SIGN(gsLocal_1, "files=" + aux1 + "&filesInfo=" + aux2 + "&bucket=song");
                gsLocal_2 = "files=" + URLEncoder.encode(aux1) + "&_time=" + gsLocal_1 + gsLocal_3 + "&filesInfo=" + URLEncoder.encode(aux2) + "&bucket=song";
                gsLocal_1 = "/api/upload/transaction";
//gsLocal_2 = "_time=1475541114&_sign=454cfcf6b8f1d28f7aadd3dacd2910b5&files=%5B%7B%22filename%22%3A%22AM_11539554_14755411134227982.jpg%22%2C%22size%22%3A46175%7D%5D&bucket=avatar";
                gsLocal_1 = WriteToSvr(HTTP_POST, gsLocal_1, gsLocal_2);
//MLOG("2:" + gsLocal_2);MLOG("3:" + URLDecoder.decode(gsLocal_2));MLOG("return 3:" + gsLocal_1);
                MakeStdReturn(gsLocal_1, resultNet);
                break;

            case APPC_UPLOAD_MP3B:
                gsLocal_3 = MUTIL.GET_HAO_CHANG_SIGN(gsLocal_1, "uploadResponse=" + aux1 + "&transactionId=" + aux2);
                gsLocal_2 = "_time=" + gsLocal_1 + gsLocal_3 + "&uploadResponse=" + URLEncoder.encode(aux1) + "&transactionId=" + URLEncoder.encode(aux2);
                gsLocal_1 = "/api/upload/transaction";
//gsLocal_2 = "_time=1475541114&_sign=454cfcf6b8f1d28f7aadd3dacd2910b5&files=%5B%7B%22filename%22%3A%22AM_11539554_14755411134227982.jpg%22%2C%22size%22%3A46175%7D%5D&bucket=avatar";
                gsLocal_1 = WriteToSvr(POST_DELETE, gsLocal_1, gsLocal_2);
//MLOG("5:" + gsLocal_2);
//MLOG("6:" + URLDecoder.decode(gsLocal_2));
//MLOG("return 6:" + gsLocal_1);
                MakeStdReturn(gsLocal_1, resultNet);
                break;

            case APPC_WANT_RANK:
                gsLocal_3 = MUTIL.GET_HAO_CHANG_SIGN(gsLocal_1, "&isShare=1&songId=" + aux1);
                gsLocal_2 = "_time=" + gsLocal_1 + "&isShare=1&songId=" + aux1 + gsLocal_3;
                gsLocal_1 = "/api/song/want/rank";
                gsLocal_1 = WriteToSvr(HTTP_POST, gsLocal_1, gsLocal_2);
//MLOG("return 8:" + gsLocal_1);
                gsLocal_2 = MUTIL.GET_JSON_STRING(gsLocal_1, "errno");
                if ("0".equals(gsLocal_2)) {
                    resultNet.message = "ok";
                }
                else if ("2152".equals(gsLocal_2)) {
                    resultNet.message = MUTIL.GET_JSON_STRING(gsLocal_1, "error");
                    MSTRING("return 8: " + resultNet.sucess + " " + resultNet.message);
                }
                else {
                    resultNet.message =  "error:" + gsLocal_2 + ":" + MUTIL.GET_JSON_STRING(gsLocal_1, "error");
                    resultNet.sucess = false;
                }
                break;
            case APPC_PUSH_MAP:
                gsLocal_2 = "pushId=ead26edd073f9da726dd73ba00445340";
                gsLocal_3 = MUTIL.GET_HAO_CHANG_SIGN(gsLocal_1, gsLocal_2 + "&deviceType=android&vendor=getui");
                gsLocal_3 = gsLocal_2 + "&_time=" + gsLocal_1 + gsLocal_3 +  "&deviceType=android&vendor=getui";
                gsLocal_1 = "/api/user/push/map";
                gsLocal_1 = WriteToSvr(HTTP_POST, gsLocal_1, gsLocal_3);
                MakeStdReturn(gsLocal_1, resultNet);
                break;
            case APPC_ADD_CARE:
            case APPC_DEL_CARE:
                gsLocal_2 = "&userId=" + aux1;
                gsLocal_3 = MUTIL.GET_HAO_CHANG_SIGN(gsLocal_1, gsLocal_2);
                gsLocal_3 = "_time=" + gsLocal_1 + gsLocal_3 + gsLocal_2;
                gsLocal_1 = "/api/my/follow";
                // X-HTTP-Method-Override: DELETE
                gsLocal_1 = WriteToSvr((type==APPC_DEL_CARE) ? POST_DELETE : HTTP_POST, gsLocal_1, gsLocal_3);
                MakeStdReturn(gsLocal_1, resultNet);
                break;
            case APPC_SAY_HELLO:
                gsLocal_2 = "&message=" + aux2 + "&userId=" + aux1;
                gsLocal_3 = MUTIL.GET_HAO_CHANG_SIGN(gsLocal_1, gsLocal_2);
                gsLocal_2 = "_time=" + gsLocal_1 + "&message=" + URLEncoder.encode(aux2) + gsLocal_3 + "&userId=" + aux1;
                gsLocal_1 = "/api/user/hello";
                gsLocal_1 = WriteToSvr(HTTP_POST, gsLocal_1, gsLocal_2);
                MakeStdReturn(gsLocal_1, resultNet);
                break;
            case APPC_PUT_FLOWER:
                gsLocal_2 = "&songId=" + aux1 + "&flower=1";
                gsLocal_3 = MUTIL.GET_HAO_CHANG_SIGN(gsLocal_1, gsLocal_2);
                gsLocal_3 = "_time=" + gsLocal_1 + "&songId=" + aux1 + gsLocal_3 + "&flower=1";
                gsLocal_1 = "/api/song/flower";
                gsLocal_1 = WriteToSvr(HTTP_POST, gsLocal_1, gsLocal_3);
//MLOG("APPC_PUT_FLOWER " + gsLocal_1);
                if (MakeStdReturn(gsLocal_1, resultNet)){
                    resultNet.message = MUTIL.GET_JSON_STRING(resultNet.nextJason, "flower");
                }
                break;
            case APPC_PUT_COMMENT:
                gsLocal_2 = "&content=" + aux2 + "&threadId=" + aux1;
                gsLocal_3 = MUTIL.GET_HAO_CHANG_SIGN(gsLocal_1, gsLocal_2);
                gsLocal_3 = "_time=" + gsLocal_1 + "&content=" +  URLEncoder.encode(aux2) + gsLocal_3 + "&threadId=" + aux1;
                gsLocal_1 = "/api/comments";
                gsLocal_2 = WriteToSvr(HTTP_POST, gsLocal_1, gsLocal_3);
                MSTRING("APPC_PUT_COMMENT " +aux1+" _ "+ aux2+" _ "+ gsLocal_2 +" "+resultNet.message);
                MakeStdReturn(gsLocal_2, resultNet);
                break;
        }
        return resultNet;
    }
    public BCommInfo MakeACommInfo(JSONArray jsonArray, int counter){
        BCommInfo bCommInfo = new BCommInfo();
        try {
            JSONObject jsonobject = jsonArray.getJSONObject(counter);
            bCommInfo.aUserInfo = new BUserInfo();
            bCommInfo.aUserInfo.userID = jsonobject.getString("userId");
            bCommInfo.aUserInfo.nickName = jsonobject.getString("nickname");
//MLOG("content1 " + bCommInfo.aUserInfo.UserName);
            String gsLocal_2 = jsonobject.getString("avatar");
            bCommInfo.aUserInfo.headUrl = MUTIL.GET_JSON_STRING(gsLocal_2, "original");
//MLOG("content2 " + bCommInfo.aUserInfo.HeadUrl);
          gsLocal_2 = jsonobject.getString("location");
            bCommInfo.aUserInfo.province = MUTIL.GET_JSON_STRING(gsLocal_2, "Province");
            bCommInfo.aUserInfo.city = MUTIL.GET_JSON_STRING(gsLocal_2, "City");
            bCommInfo.aUserInfo.longitude = MUTIL.GET_JSON_STRING(gsLocal_2, "longitude");
            bCommInfo.aUserInfo.latitude = MUTIL.GET_JSON_STRING(gsLocal_2, "latitude");
//MLOG("content3 " + bCommInfo.aUserInfo.City);
            bCommInfo.commentID = jsonobject.getString("commentId");
            bCommInfo.content = jsonobject.getString("content");
//MLOG("content4 " + bCommInfo.content);
            bCommInfo.createTime = jsonobject.getString("CreateTime");
            bCommInfo.totalReply = jsonobject.getString("totalReply");
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return bCommInfo;
    }

    public boolean MakeStdReturn(String gsLocal_1, ResultNet resultNet) {
        String gsLocal_2 = MUTIL.GET_JSON_STRING(gsLocal_1, "errno");
        if ("0".equals(gsLocal_2)) {
            resultNet.nextJason = MUTIL.GET_JSON_STRING(gsLocal_1, "data");
//MDWORD(0xb1);MLOG(resultNet.nextJason);
            return true;
        }
        resultNet.message =  "error:" + gsLocal_2 + ":" + MUTIL.GET_JSON_STRING(gsLocal_1, "error");
        resultNet.sucess = false;
        return false;
    }
    public String WriteToSvr(int type, String destUrl, String param) {
        String gsLocal_1 = "";
        BufferedInputStream bis = null;
        HttpURLConnection mHttpUrl=null;
    //    URLConnection mHttpUrl=null;
        URL url = null;
        byte[] gLocal_Buffer = new byte[0x100000+1460];

        try {
            url = new URL("http://api.haochang.tv" + destUrl);
            mHttpUrl = (HttpURLConnection) url.openConnection();
            mHttpUrl.setConnectTimeout(30000);
            mHttpUrl.setReadTimeout(30000);

            mHttpUrl.setRequestProperty("app-channel", "mc");
            mHttpUrl.setRequestProperty("app-version", "4.3.2");
            mHttpUrl.setRequestProperty("cli-uniqid", gs_cli_uniqid);
            mHttpUrl.setRequestProperty("cli-idfa", "");
            mHttpUrl.setRequestProperty("cli-os", "android");
            mHttpUrl.setRequestProperty("cli-os-version", "4.3");
            mHttpUrl.setRequestProperty("cli-model", gs_cli_model);
            mHttpUrl.setRequestProperty("cli-resolution", "720*1280");
            if ((type & HTTP_GET) > 0) {
                mHttpUrl.setRequestProperty("cli-mcc", "");
                mHttpUrl.setRequestProperty("cli-mnc", "");
            }
            else {
                mHttpUrl.setRequestProperty("cli-mcc", "460");
                mHttpUrl.setRequestProperty("cli-mnc", "01");
            }
            if ((type & POST_PUT) > 0) {
                mHttpUrl.setRequestProperty("X-HTTP-Method-Override", "PUT");
            }
            else if ((type & POST_DELETE) > 0) {
                mHttpUrl.setRequestProperty("X-HTTP-Method-Override", "DELETE");
            }
             mHttpUrl.setRequestProperty("cli-lng", gsLongitude);
            mHttpUrl.setRequestProperty("cli-lat", gsLatitude);
            mHttpUrl.setRequestProperty("cli-wifi", "1");
            mHttpUrl.setRequestProperty("User-Agent", "");

//MLOG("HTTP_GET= 1 " + LoginFlag + " "+type);
            if ((type & GET_REMIND) > 0){
//MLOG("HTTP_GET= 2 " + LoginFlag + " "+type);
                mHttpUrl.setRequestProperty("authorize-token", CodeBase64.encodeBytes(gsMixAccount.getBytes()));
            }
            else if (((type & NO_LOGIN) == 0 && !"".equals(gsMixAccount))){
                mHttpUrl.setRequestProperty("authorize-token", CodeBase64.encodeBytes(gsMixAccount.getBytes()));
            }

            mHttpUrl.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
            mHttpUrl.setRequestProperty("Connection", "Keep-Alive");
            mHttpUrl.setRequestProperty("Accept-Encoding", "gzip");

            mHttpUrl.setDoInput(true);
            if ((type & HTTP_GET) > 0){
                mHttpUrl.setDoOutput(false);
                mHttpUrl.setUseCaches(false);
                mHttpUrl.setRequestMethod("GET");
            }
            else  {
                mHttpUrl.setDoOutput(true);
                mHttpUrl.setUseCaches(false);
                mHttpUrl.setRequestMethod("POST");
                DataOutputStream dos=new DataOutputStream(mHttpUrl.getOutputStream());
                dos.writeBytes(param);
                dos.flush();                    // 刷新对象输出流，将任何字节都写入潜在的流中（些处为ObjectOutputStream）
                dos.close();                    // 关闭流对象。此时，不能再向对象输出流写入任何数据，先前写入的数据存在于内存缓冲区中,
            }
            // 再调用下边的getInputStream()函数时才把准备好的http请求正式发送到服务器
            int responseCode = 0;
            try {
                responseCode = mHttpUrl.getResponseCode();
            } catch (IOException e) {
            }
            if (responseCode == 200 || responseCode == 201) {
                bis = new BufferedInputStream(mHttpUrl.getInputStream());     // 注意，实际发送请求的代码段就在这里
            }
            else {
                bis = new BufferedInputStream(mHttpUrl.getErrorStream());     // 注意，实际发送请求的代码段就在这里
            }

            int size = 0;
            int g4Local_1 = 0;
            while ((size = bis.read(gLocal_Buffer, g4Local_1, 1460)) != -1) {
                if (size > 0){
                    g4Local_1 += size;
                    if (g4Local_1 >= 0x100000){
                        break;
                    }
                }
            }
            bis.close();
            if (g4Local_1 > 0){
                gsLocal_1 = new String(gLocal_Buffer, 0, g4Local_1, "utf-8");
            }
            NetworkError = 0;
            mHttpUrl.disconnect();
        } catch (IOException e) {
            ++NetworkError;
        }
        return gsLocal_1;
    }
    @Override
    public byte[] MixAccountToBuffer(String mixAccount, String userID) {     // "11641250,1477885995,a962b73b958d9b0fd4474de357019af2"
        byte gpLocal_1[];
        if (!"".equals(userID)){
            gpLocal_1 = new byte[28];
            MAPI.DWORD_BUFF8(MAPI.STRING_DEC32(userID), 24, gpLocal_1);
        }
        else {
            gpLocal_1 = new byte[24];
        }
        String[] params = mixAccount.split(",");
        if (params.length > 2){
            MAPI.DWORD_BUFF8(MAPI.STRING_DEC32(params[0]), 0, gpLocal_1);
            MAPI.DWORD_BUFF8(MAPI.STRING_DEC32(params[1]), 4, gpLocal_1);
            SubUtils sysUtils = new SubUtils();
            sysUtils.fromAsciiStringToHex(params[2], 16, 8, gpLocal_1);
        }
        return gpLocal_1;
    }
    @Override
    public String Base64MixAccount(String base64) {
        if (base64 != null && !"".equals(base64)) {
            if (base64.length() > 4) {
                String gsLocal_1;
                byte gpLocal_1[];
                SubUtils sysUtils = new SubUtils();
                try {
                    gpLocal_1 = CodeBase64.decode(base64.getBytes());
//MLOG(gpLocal_1.length);
                    if (gpLocal_1.length >= 24) {
                        gsLocal_1 = sysUtils.fromHexStringAscii(16, 8, gpLocal_1);
                        return String.format("%d,%d,%s", MAPI.BUFF8_DWORD(0, gpLocal_1), MAPI.BUFF8_DWORD(4, gpLocal_1), gsLocal_1);
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        MLOGE("KgHaoChang Base64MixAccount error "+base64);
        return " eeeeeee ";
    }
    public final int Tab_SkipUserID[] = {
        11667034, 11542913, 11673075, 10304064, 11677271, 11677280, 11676913, 11680481, 11666862, 10778508, 11667119, 11676876, 11547656,
    };
    @Override
    public boolean IsSkipUserList(String userID) {
        if ("".equals(userID)){
            return true;
        }
        if (gsUserID.equals(userID)){
            return true;
        }
        int g4UserID = MAPI.STRING_DEC32(userID);
        int g4Local_1 = Tab_SkipUserID.length;
        int g4Local_2 = 0;
        do {
            if (Tab_SkipUserID[g4Local_2] == g4UserID){
                return true;
            }
        } while (++g4Local_2 < g4Local_1);
        return false;
    }

}
